# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  #
  # 円のフォーマット
  #
  def fmt_yen(yen)
    fmt_num(yen) + ' 円'
  end
  
  def fmt_num(num)
    str = num.to_s
    if str.to_s =~ /^\d+\.?\d*$/
      sprintf("%0.0f", str).reverse.scan(/.?.?./).join(',').reverse
    else
      str
    end
  end
  
  #
  # 日付のフォーマット(yyyy/MM/dd)
  #
  def fmt_date(date)
    date.strftime("%Y/%m/%d")
  end
  
  def fmt_datetime(dt)
    dt.strftime("%Y-%m-%d %H:%M")
  end
  
  def fmt_user_name(id)
    return "" if id.nil? 

    user = User.find_by_id(id)
    user.nil? ? "" : user.name
  end
  
  
  def jquery_tag
    '<script type="text/javascript" src="/javascripts/jquery/jquery.js"></script>'
  end
  
  def curvycorners_tag
    '<script type="text/javascript" src="/javascripts/curvycorners.js"></script>'  
  end
  
  def datepicker_tag
    '<script type="text/javascript" src="/javascripts/jquery/ui.datepicker.js"></script>\n' +
    '<link type="text/css" rel="stylesheet" media="screen" href="/stylesheets/ui.datepicker.css">'
  end
end

